package com.zhangwei.liwushuo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.zhangwei.liwushuo.R;
import com.zhangwei.liwushuo.bean.CateGoryGroupEntity;
import com.zhangwei.liwushuo.bean.ChannelsEntity;
import com.zw.library.view.GridViewForScrollView;

import java.util.List;

/**
 * @说 明：
 * @项目名称：LiWuShuo
 * @包 名： com.zhangwei.liwushuo.adapter
 * @类 名： CategoryExpAdapter
 * @创 建人： zhangwei
 * @创建时间：2015-08-20 23:54
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class CategoryExpAdapter extends BaseExpandableListAdapter {

    List<CateGoryGroupEntity> list;

    private LayoutInflater inflater;

    private Context context;


    public CategoryExpAdapter(List<CateGoryGroupEntity> list, Context context) {
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getGroupCount() {
        return list.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return 1;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        GroupViewHolder gvh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_cate_group_layout, parent, false);
            gvh = new GroupViewHolder(convertView);
            convertView.setTag(gvh);

        } else {
            gvh = (GroupViewHolder) convertView.getTag();
        }
        gvh.nameTv.setText(list.get(groupPosition).getName());

        return convertView;
    }
    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ChildeViewHolder cvh;
        List<ChannelsEntity> channels = list.get(groupPosition).getChannels();
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_cate_gv_layout, parent, false);
            cvh = new ChildeViewHolder(convertView);
            convertView.setTag(cvh);

        } else {
            cvh = (ChildeViewHolder) convertView.getTag();
        }

        CategoryGvAdapter adapter = new CategoryGvAdapter(channels, inflater, context);
        cvh.gridView.setAdapter(adapter);

        return convertView;

    }

    private static class GroupViewHolder {
        TextView nameTv;

        public GroupViewHolder(View convertView) {
            nameTv = (TextView) convertView.findViewById(R.id.item_cate_group_name);
        }
    }

    private class ChildeViewHolder {
        private GridViewForScrollView gridView;
        public ChildeViewHolder(View convertView) {
            gridView = (GridViewForScrollView) convertView.findViewById(R.id.item_cate_child_gv);
        }
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }


}
